<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv=Content-Type>
<title><?=lang('system_adminname')?> - Powered by <?=lang('system_name')?> <?=lang('system_version')?></title>
<style type="text/css">
*{padding:0;margin:0;}
div{margin:0;padding:0;}
body{background:#efeff1;color:#135891;font-size:14px;font-weight:800;}
#body{width:449px;height:268px;overflow:hidden;background:url(<?=base_url('images/loginbody.gif')?>) no-repeat;margin:150px auto;}
table{margin-top:40px;margin-left:90px;line-height:24px;position:absolute;}
td{padding:0 0 0 3px;}
#user_name,#user_pass{width:150px;height:24px;line-height:24px;}
#captcha{width:150px;height:24px;line-height:24px;float:left;}
#authcode{height:24px;float:right;cursor:pointer;}
#authcode_result{float:right;}
#msgtip{width:190px;float:left;color:red;}
#loginbtn{position:relative;width:70px;height:28px;float:left;margin-left:50px;text-align:center;line-height:28px;color:#fff;text-decoration:none;background:url(<?=base_url('images/loginbg.gif')?>) no-repeat;}
.footer{color:#9F9F9F;text-align: right;font-size: 11px;line-height: 20px;}
.footer a{color:#7EB4FE;}
</style>
</head>
<body>
<div id="body">
<form action="" autocomplete="off">
<table border="0">
<tr>
	<td height="40" valign="top" align="right">
		<?=lang('user_name')?></td><td valign="top" align="left">
		<input type="text" name="user_name" id="user_name" value="" onpaste="return false" ondragenter="return false">
		<input type="hidden" id="hash" name="hash" value="<?=$encrypted_string?>">
	</td>
</tr>
<tr>
	<td height="40" valign="top" align="right"><?=lang('user_pass')?></td>
	<td valign="top" align="left">
		<input type="password" name="user_pass" id="user_pass" value="" onpaste="return false" ondragenter="return false">
	</td>
</tr>
<tr>
	<td height="40" valign="top" align="right">验证码</td>
	<td valign="top" align="left">
		<input type="text" name="captcha" id="captcha" value="" onblur="ajaxauth();">
		<img id="authcode" src="<?php echo site_url().'imgauthcode/show';?>" onclick="refresh('imgauthcode/show')"/>
		<span id="authcode_result"></span>
	</td>
</tr>
<tr><td colspan="2" height="50" valign="top">
	<a href="javascript:void(0)" onclick="login()" id="loginbtn"><?=lang('btn_login')?></a>
	<span id="msgtip"></span>
</td></tr>
<tr><td colspan="2" height="20" class="footer"><?=lang('system_copy')?>  Powered by <a href="<?=lang('system_link')?>" target="_blank"><?=lang('system_name')?></a></td></tr>
</table>
</form>
</div>
</body>
<script type="text/javascript" src="<?=base_url('js/jquery.min.js')?>"></script>
<script type="text/javascript" src="<?=base_url('js/rsa.js')?>"></script>
<script type="text/javascript">
window.onload = function(){
	$("#user_name").select();
	$("#user_name").focus();
}

function login(){
	var user_name=$.trim($("#user_name").val());
	var user_pass=$.trim($("#user_pass").val());
	user_name = encryptedString(key, user_name);
	user_pass = encryptedString(key, user_pass);
	var captcha = $('#captcha').val();
	var encrypted_string = $('#hash').val();
	$.trim($("#user_pass").val(user_pass));
	if(captcha.length != 4 || ajaxauth() == 0)
	{
		$("#msgtip").html("验证码有误");
		return false;
	}
	$.ajax({
		type: "POST",
		url: "<?=site_aurl('main/login')?>",
		data: "opt=ajax&user_name="+user_name+"&user_pass="+user_pass+"&captcha="+captcha+"&encrypted_string="+encrypted_string,
		success: function(msg){
			if(msg=='ok'){
				<?php if (isset($lose)&&$lose==1): ?>
				location.href=document.referrer
				<?php else: ?>
				location.href="<?=site_aurl('main')?>";
				<?php endif; ?>
			}
			else if(msg=='time_out'){
				$("#msgtip").html("页面已过期，请刷新页面");
				flashing();
			}
			else if(msg=='code_error'){
				$("#msgtip").html("验证码有误");
				flashing();
			}
			else{
				$("#msgtip").html("<?=lang('name_or_pass_error')?>");
				flashing();
			}
		},
		beforeSend:function(){
			$("#msgtip").html("<?=lang('user_logining')?>");
		},
		error:function(XMLHttpRequest, textStatus, errorThrown){
			$("#msgtip").html(errorThrown);
			flashing();
		}
	});
}
function flashing(){
	$("#msgtip").hide(200);
	$("#msgtip").show(200);
	$("#msgtip").hide(200);
	$("#msgtip").show(200);
	$("#msgtip").hide(200);
	$("#msgtip").show(200);
}
$(document).keypress(function(e) {
if (e.which == 13)  
	login(); 
});

function refresh()
{
	var url='<?php echo site_url()."/imgauthcode/show/";?>'+Math.random();
	$('#authcode').attr('src', url);
}
function ajaxauth()
{
	var authcode = $('#captcha').val();
	$.get("<?php echo site_url()."imgauthcode/check/";?>"+authcode, function(data){		
		if(data)
		{
			$('#authcode_result').text("正确");
			return 1;
		}
		 else
		 {
			$('#authcode_result').text("错误");
			return 0;
		 }
	}); 
}
</script>
</html>